$(document).ready(function ()
{
    $('#search').keydown(function (e) {
        if (this.value) {
            $('#progressbar').css("width", '50%');
            $('#progressbar').removeClass();
            $('#progressbar').addClass("progress-bar progress-bar-warning progress-bar-striped active");
            $('#info').html("Appuyez sur Entrée ou cliquez sur 'Go!'");
        }
    });


    $('#search').on('input', function (e) {
        if (!this.value) {
            $('#progressbar').css("width", '1%');
            $('#progressbar').removeClass();
            $('#progressbar').addClass("progress-bar progress-bar-danger progress-bar-striped active");
            $('#info').html('Saisissez votre recherche');
        }
    });


    $('#formulaire').submit(function (event) {
        if ($('#search').val()) {
            $('#progressbar').css("width", '100%');
            $('#progressbar').removeClass();
            $('#info').html('<b>Voici les résultats :</b>');
            $('#progressbar').addClass("progress-bar progress-bar-success progress-bar-striped active");
            $.post("search.php", $(this).serialize()).done(function (msg) {
                $("#results").html(msg);
            });
        }
        return false;
    });
    
    //Une requête provient de la barre de recherche du menu
    if($('#search').val().length)
    {
        $("#formulaire").submit();
    }
});

